package com.bootdo.common.fansheutils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.bootdo.common.annotation.NotColumn;
import com.google.common.base.CaseFormat;
/**
 * @author haojiangbo
 * @email 2100272728@qq.com
 * @date 2018-11-29 23:45:30
 *
 */
public class FansheUtils {
	
	@SuppressWarnings("unchecked")
	public static List<HashMap<String,Object>> getFieldList(Object obj) {
		List<HashMap<String,Object>> list = new ArrayList<HashMap<String,Object>>();
 		try {
			Field [] f = obj.getClass().getDeclaredFields();
			if(null != f && f.length > 0) {	
				for(Field fh: f) {
					HashMap<String,Object> fl = new HashMap<String,Object>();
					NotColumn notColumn = fh.getAnnotation(NotColumn.class);
					if(null == notColumn || notColumn.value()==false){	
						fh.setAccessible(true);
						fl.put("k", CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, fh.getName()));
						fl.put("v", fh.get(obj));
						list.add(fl);
					}
				}				
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
 		return list;
	}	
}
